<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>ES5的面向对象编程</title>
</head>
<body>
<script>
function Point(x, y){
    this.x = x;
    this.y = y;
}
// 给父级绑定方法
Point.prototype.toSting = function(){
    return '(' + this.x + ',' + this.y + ')';
}
var p = new Point(10, 20);
console.log(p.x)
console.log(p.toSting());
// 继承
function ColorPoint(x, y, color){
    Point.call(this, x, y);
    this.color = color;
}
// 继承父类的方法
ColorPoint.prototype = Object.create(Point.prototype);
// 修复 constructor
ColorPoint.prototype.constructor = Point;
// 扩展方法
ColorPoint.prototype.showColor = function(){
    console.log('My color is ' + this.color);
}
var cp = new ColorPoint(10, 20, "red");
console.log(cp.x);
console.log(cp.toSting());
cp.showColor()
</script>	
</body>
</html>